package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.Address;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Region;
import com.cskaoyan.bean.wx.AddressEditVo;
import com.cskaoyan.service.wx.AddressService;
import com.cskaoyan.utils.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/wx")
public class WxAddressController {

    @Autowired
    AddressService addressService;

    @RequestMapping("/address/list")
    public BaseRespVo AddressList(){
        Integer userId = IdUtils.getId();

        List<Address> addressList = addressService.addressList(userId);
        return BaseRespVo.ok(addressList);
    }

    @RequestMapping("/region/list")
    public BaseRespVo regionList(Integer pid){
        List<Region> regions = addressService.regionList(pid);
        return BaseRespVo.ok(regions);
    }

    @RequestMapping("/address/save")
    public BaseRespVo addressSave(@RequestBody Address address){
//        address.setUserId(UserInfo.USER_ID);
        address.setUserId(IdUtils.getId());
        address.setAddTime(new Date());
        address.setUpdateTime(new Date());
        addressService.addressSave(address);
        return BaseRespVo.ok();
    }
    @RequestMapping("address/detail")
    public BaseRespVo addressDetail(Integer id){
        AddressEditVo addressEdit = addressService.addressDetail(id);
        return BaseRespVo.ok(addressEdit);
    }
    @RequestMapping("address/delete")
    public BaseRespVo addressDelete(@RequestBody Integer id){
        addressService.addressDelete(id);
        return BaseRespVo.ok();
    }
}
